﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.Features
{
	[Serializable]
	public class Feature : IFeature
	{
		public static bool ComputeBoundingBoxWhenItIsMissing { get; set; }

		public Feature(IGeometry geometry, IAttributesTable attributes) : this()
		{
			this._geometry = geometry;
			this._attributes = attributes;
		}

		public Feature()
		{
		}

		public virtual IGeometry Geometry
		{
			get
			{
				return this._geometry;
			}
			set
			{
				this._geometry = value;
			}
		}

		public virtual IAttributesTable Attributes
		{
			get
			{
				return this._attributes;
			}
			set
			{
				this._attributes = value;
			}
		}

		public Envelope BoundingBox
		{
			get
			{
				if (this._boundingBox != null)
				{
					return new Envelope(this._boundingBox);
				}
				if (this._geometry != null && Feature.ComputeBoundingBoxWhenItIsMissing)
				{
					return this._geometry.EnvelopeInternal;
				}
				return null;
			}
			set
			{
				this._boundingBox = value;
			}
		}

		private IGeometry _geometry;

		private IAttributesTable _attributes;

		private Envelope _boundingBox;
	}
}
